package com.ahammertest.ycgk.wxapi;

import android.app.Activity;

import com.shuoyue.ycgk.MyApplication;
import com.tencent.mm.opensdk.modelpay.PayReq;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

public class WxPay {

    /**
     * {
     * "package": "Sign=WXPay",
     * "appid": "wx8a0ede166cd8eed2",
     * "sign": "9A0D052509EB2E9E5ADED74E83FAC1C3",
     * "partnerid": "1555608141",
     * "prepayid": "wx2221483415191633e212c8841925817100",
     * "noncestr": "vI8o6jrRcCDh89NDFrXczd31ApguA88Y",
     * "timestamp": "1569160114"
     * }
     *
     * @param context
     * @param info
     */
    public static void pay(Activity context, WxPayBean info) {


        PayReq req = new PayReq();
        req.appId = info.getAppid();//你的微信appid
        req.partnerId = info.getPartnerid();//.get("partnerid");//商户号
        req.prepayId = info.getPrepayid();//.get("prepayid");//预支付交易会话ID
        req.nonceStr = info.getNoncestr();//.get("noncestr");//随机字符串
        req.timeStamp = info.getTimestamp();//.get("timestamp");//时间戳\
        req.extData = info.getExtdata();
        req.signType = "MD5";
        req.packageValue = info.getPackageX();// info.getPackageX();//"Sign=WXPay";//扩展字段, 这里固定填写Sign = WXPay
        req.sign = info.getSign();//.get("sign");//签名
//        req.extData = "app data"; // optional
        // 在支付之前，如果应用没有注册到微信，应该先调用IWXMsg.registerApp将应用注册到微信
        MyApplication.getInstance().api.sendReq(req);
    }
}